package com.web.controller.web;

import com.web.dao.PoundageConfigMapper;
import com.web.dao.ProfitConfigMapper;
import com.web.domain.WebResponse;
import com.web.entity.PoundageConfig;
import com.web.entity.ProfitConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author FDjavaone
 * @date 2017/9/29
 */
@Slf4j
@Controller
public class WebSystemConfigController {
    @Autowired
    private ProfitConfigMapper profitConfigMapper;

    @Autowired
    private PoundageConfigMapper poundageConfigMapper;


    @RequestMapping(value = "sysm/config",
            method = RequestMethod.GET)
    public String config(Model model, HttpServletRequest request) {
        return "config";
    }

    @RequestMapping("/sysm/getConfig")
    @ResponseBody
    public WebResponse getConfig() {
        ProfitConfig config = profitConfigMapper.selectByPrimaryKey(1L);
        PoundageConfig poundageConfig = poundageConfigMapper.selectByPrimaryKey(1L);
        Map map = new HashMap();
        map.put("config", config);
        map.put("poundageConfig", poundageConfig);
        return WebResponse.ok("操作成功", map);
    }

    @RequestMapping("/sysm/updateConfig")
    @ResponseBody
    public WebResponse updateConfig(ProfitConfig profitConfig) {
        Date date = new Date();
        profitConfig.setId(1L);
        profitConfig.setModifyTime(date);
        profitConfigMapper.updateByPrimaryKeySelective(profitConfig);
        return WebResponse.ok("操作成功");
    }


    @RequestMapping("/sysm/updatePoundageConfig")
    @ResponseBody
    public WebResponse updatePoundageConfig(PoundageConfig poundageConfig) {
        Date date = new Date();
        poundageConfig.setId(1L);
        poundageConfig.setModifyTime(date);
        poundageConfigMapper.updateByPrimaryKeySelective(poundageConfig);
        return WebResponse.ok("操作成功");
    }
}
